// name: 下载的文件名
// blob 下载的文件的blob 二进制数据格式的文件
export function downloadFile(name, blob) {
    const urlObject = window.URL || window.webkitURL || window;
    const downloadData = new Blob([blob]);
    const save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
    save_link.href = urlObject.createObjectURL(downloadData);
    save_link.download = name;
    fake_click(save_link);
}

function fake_click(obj) {
    const ev = document.createEvent("MouseEvents");
    ev.initMouseEvent(
        "click", true, false, window, 0, 0, 0, 0, 0
        , false, false, false, false, 0, null
    );
    obj.dispatchEvent(ev);
}